package com.ereach;

import java.util.HashMap;
import java.util.Map;

public class DemoHashMap {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();

        map.put("one", 1);
        map.put("two", 2);
        map.put("three", 3);
        map.put("four", 4);
        map.put("five", 5);
        map.put("six", 6);

        System.out.println(map);

        System.out.println("get the size of a map");
        System.out.println(map.size());

        System.out.println("get map value by name");
        System.out.println(map.get("two"));

        System.out.println("check map if contains key");
        System.out.println(map.containsKey("four"));

        System.out.println("check map if contains value");
        System.out.println(map.containsValue(2));

        System.out.println("remove map element by key");
        map.remove("two");
        System.out.println(map);

        System.out.println("remove map element by given key and value");
        boolean isRemoved = map.remove("four", 5);
        System.out.println(isRemoved);

        System.out.println("return null if remove key does not found");
        System.out.println(map.remove("ten"));

        System.out.println("entrySet");
        System.out.println(map.entrySet());

        System.out.println("print all keys of the map");
        System.out.println(map.keySet());

        System.out.println("print all values of the map");
        System.out.println(map.values());

        System.out.println("lambda forEach of the map");
        map.forEach((name, value) -> System.out.println(name + " => " +value));

        System.out.println("for each from map key set");
        for (var name : map.keySet())
            System.out.println(map.get(name));
    }
}
